<template>
  <div style="padding:10px;height:100%; ">
    <el-form :inline="true">

      <el-form-item>
        <el-button
          type="primary"
          @click="setLock"
          icon="delete"
        >锁表/取消锁表</el-button>

      </el-form-item>
  
    </el-form>
    <el-table
      style="width:100%"
      :data="list"
      height="500px"
      v-loading="listLoading"
      element-loading-text="Loading"
      ref="table"
      @selection-change="changeFun"
      border
    >
      <el-table-column
        type="selection"
        width="55"
        align="center"
        class="selection"
        prop='uuid'
      ></el-table-column>
      <el-table-column
        align="center"
        type="index"
        width="50"
        label="序号"
        fixed="left"
      >
        <template slot-scope="scope">
          <span>{{(currentPage- 1) * pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>

      <DataListItem
        v-bind:key="$index"
        v-for="(item,$index) in cols"
        :column="item"
      />

    </el-table>
    <el-pagination
      align="right"
      style="margin-top:20px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[ 200]"
      :page-size="pageSize"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="list.length"
    >
    </el-pagination>

  </div>
</template>
<script>
import Vue from "vue";
import request from "@/utils/request";
import { getUser } from "@/utils/auth";
import linq from "linq";
import axios from "axios";
import { getLock,addLock, updateLock } from "@/api/权限";
import { get登录日志 } from "@/api/权限.js";
import { uuid } from "vue-uuid";
export default {
  components: {
    DataListItem: {
      name: "DataListItem",
      template: `<el-table-column :label='column.label' :prop='column.prop' align="center">
          
          <DataListItem :key="$index" v-for="(item,$index) in column.data?column.data:[]" :column="item" />
          </el-table-column>
          `,
      props: ["column"]
    }
  },
  data: function() {
    return {
      model: {},
      search_str: "",
      cols: [{ label: "表名", prop: "TABLENAME" }, { label: "锁定", prop: "LOCK" }],
      listLoading: true,
      list: [],

      multipleSelectionDelete: [],
      multipleSelection: [],
      currentPage: 1,
      pageSize: 20,
      user: null
    };
  },

  async created() {
    //

    this.listLoading = true;
    let locks = await getLock(this.$root.user.XXID, this.$root.user.CJPC);
    
    if (locks.length == 0) {
      var temp = [
        "1.1 名称",
        "1.2 联系",
        "1.3 招生计划",
        "1.4 招生方式",
        "1.5 当年9月1日前在校生",
        "1.6 机构设置",
        "2.1 基本情况",
        "2.2 参与教学联系学生",
        "3.1 占地、建筑面积",
        "3.2 馆藏图书资料",
        "3.3 阅览室、机房、教室",
        "3.4.1 信息化建设概况",
        "3.4.2 管理信息系统",
        "3.4.3 信息化工作机构与人员",
        "3.5 固定资产",
        "4.1 校内实践基地",
        "4.2 校外实习实训基地",
        "4.3 职业技能鉴定机构",

        "5.1.1 学费收入",
        "5.1.2 财政经常性补助收入",
        "5.1.3 中央、地方财政专项投入",
        "5.1.4 其他收入",
        "5.1.5 学校总收入中其他情况",
        "5.2.1 教学改革及研究",
        "5.2.2 师资建设",
        "5.2.3 其他支出",
        "6.1 教师基本情况",
        "6.2 教师授课情况",
        "6.3 教师其他情况",
        "7.1.1 开设专业",
        "7.1.2 专业带头人",
        "7.1.3 专业负责人",
        "7.2 课程设置",
        "7.3.1 职业资格证书",
        "7.3.2 应届毕业生获证及社会培训情况",
        "7.4 顶岗实习",
        "7.5.1 产学合作基本情况",
        "7.5.2 现代学徒制培养",
        "7.6.1 招生",
        "7.6.3 上届毕业生就业情况",
        "8.1 教学与学生管理文件",
        "8.2 专职教学管理人员情况",
        "8.3 专职学生管理人员情况",
        "8.4 专职招生就业指导人员情况",
        "8.5 专职督导人员情况",
        "8.6 专职教学研究人员情况",
        "8.7 评教情况",
        "8.8 奖助学情况",
        "8.9 重大制度创新",
        "9.1 招生情况",
        "9.2 就业率",
        "9.3 社会捐赠情况",
        "9.4 就业单位与联系人",
        "9.5 质量工程",
        "9.6.1 学生获奖情况",
        "9.6.2 学校获奖情况",
        "9.6.3 学生社团、红十字会获奖情况",
        "10.1.1 学生基本信息",
        "10.1.2 学生就业信息表",
        "10.2.1 辍学学生明细表",
        "10.3 学生社团",
        "10.4 红十字会",
        "10.5 志愿者活动",
        "11.1 当年专业变动情况",
        "11.2 在校学生的地区、户口所在地及民族等情况",
        "11.3 复转军人、退役军人情况",
        "11.4 少数民族教师情况",
        "11.5 补充2020-2021学年开设专业",
        "11.6 补充2020年9月后入学新生信息",

        "12.1 平台未尽事宜说明"
      ].map(e => {
        return { ID:uuid.v1(),TABLENAME: e, LOCK: "否",CJPC:this.$root.user.CJPC,XXID:this.$root.user.XXID};
      });
      var result =[];
      
      await Promise.all(temp.map(async item=>{
        var data =  await addLock(item);
        result.push(data);
      }))
      this.list = result;
    } else {
      
    this.list =  locks;
    }

    this.listLoading = false;
    //
  },

  methods: {
    changeFun(val) {
      this.multipleSelection = val;
    },
    async setLock() {
      try{
      if (this.multipleSelection.length == 0) return;
      this.listLoading = true;
      await Promise.all(this.multipleSelection.map(async item=>{
        item.LOCK == '否'? item.LOCK='是': item.LOCK='否';
         await updateLock(item);
      }))
      this.$alert("更新成功");
      }catch(e){
        this.$alert(e);
      }finally{
        this.listLoading = false;
      }
    },
    handleSizeChange: function(size) {
      this.pageSize = size;
    },
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage;
    }
  }
};
</script>